<template>
  <a-modal :width="1000" v-model:visible="showAddShopDialog" title="编辑店铺" top="8vh" :footer="false" title-align="start" :mask-closable="false" @cancel="closedDialog">
    <a-scrollbar style="height: calc(84vh - 100px); overflow: auto">
      <div style="padding: 5px; width: 960px; overflow: hidden" v-if="currentData.id">
        <EditShopBase style="margin-bottom: 10px" :userList="userList" :currentData="currentData" />
        <a-divider />
        <EditShopMarket style="margin-bottom: 10px" :userList="userList" :currentData="currentData.shopMarkets || []" :shopId="currentData.id" />
        <a-divider />
        <EditShopRegister style="margin-bottom: 10px" :currentData="currentData.shopRegister || {}" :shopId="currentData.id" />
        <a-divider />
        <EditComRegister style="margin-bottom: 10px" :currentData="currentData.shopEnterprise || {}" :shopId="currentData.id" />
      </div>
    </a-scrollbar>
  </a-modal>
</template>
<script lang="ts" setup>
  import { ref } from 'vue'
  import EditShopBase from './editShopBase.vue'
  import EditShopMarket from './editShopMarket.vue'
  import EditShopRegister from './editShopRegister.vue'
  import EditComRegister from './editComRegister.vue'
  import { getShopInfo, getOrganizesUser } from '@/api/system'

  const emit = defineEmits(['closed', 'success'])
  const props = defineProps({
    isShow: {
      type: Boolean,
      default: false,
    },
    shopId: {
      type: String,
    },
  })
  const showAddShopDialog = ref(props.isShow)
  const currentData = ref<any>({})
  const userList = ref<Array<any>>([])

  // 获取所有用户列表
  async function getUserList() {
    const res: any = await getOrganizesUser({
      pageNum: 1,
      pageSize: 1000,
    })
    userList.value = res?.data?.records || []
  }
  getUserList()
  // 获取店铺详情
  async function getShopDetail() {
    const res: any = await getShopInfo({ id: props.shopId })
    currentData.value = res?.data || {}
  }
  getShopDetail()

  // 关闭
  function closedDialog() {
    emit('closed')
    emit('success')
  }
</script>
<style lang="less" scoped></style>
